var t = function (t) {
  return t && t.__esModule ? t : {
    default: t
  };
}(require("../../../../utils/toot.js")),
  app = getApp(),
  e = 0;
var util = require("../../../../utils/util.js")


Page({
  data: {
    oldHeight: 50,
    pl_pic: [],
    data_arr: [],
    height: 50,
    urlArr: [],
    page: 0,
    prenumber: 10,
    listPatientBbsReplyVO: [],
    bigFilePath: "",
    smallFilePath: "",
    comFlag: !1,
    loadingBoo: !0,
    moreBoo: !0,
    scrollTop: 0,
    topFlag: !1,
    rcontent: "",
    huifuindex: "",
    addFlag: !0,
    imgUrlList: [],
    detailList: {},
    currindex: 0,
    listPatientBbsReplyVO: [],
    dianj: 0
  },
  xiugai: function (e) {
    console.log(e)
  },
  linechange: function (t) {
    console.log(t);
    var e = this,
      a = e.data.oldHeight;
    e.data.height;
    t.detail.lineCount > 4 || (t.detail.heightRpx > a ? e.setData({
      height: t.detail.heightRpx
    }) : e.setData({
      height: a
    }));
  },
  chooseImage: function (e) {
    var a = this,
      i = a.data.urlArr,
      o = this.data.imgUrlList;
    o.length >= 9 ? a.setData({
      addFlag: !1
    }) : t.default.chooseimageTwo(a, o, i);
    console.log(e)
  },
  delImage: function (e) {
    var a = this,
      i = this.data.imgUrlList,
      o = e.target.dataset.index;
    t.default.delImg(a, o, i);
  },
  previewImage: function (t) {
    var a = this.data.imgUrlList,
      i = t.target.dataset.imgindex;
    e.previewImage(t, a, i);
  },
  previewImg: function (t) {
    console.log(t)
    var current = t.target.dataset.src;
    //预览图片
    var imgs = []
    imgs.push(current)
    wx.previewImage({
      current: current,
      urls: imgs,
    });
  },
  criticImage: function (t) {
    var a = this.data.listPatientBbsReplyVO,
      i = t.target.dataset.imgindex,
      o = t.currentTarget.dataset.ruid;
    a && a.forEach(function (t) {
      if (t.rid == o) return a = t.estimatePicBigUrl, !1;
    }), e.previewImage(t, a, i);
  },
  goComment: function (e) {
    console.log(e)
    var that = this
    var a_id = that.data.a_id
    var t = that.data.comFlag;
    that.setData({
      comFlag: !t,
      a_id: a_id
    });
  },
  getText: function (t) {
    //console.log(t)
    this.setData({
      rcontent: t.detail.value
    });
  },
  sendBtn: function (e) {
    var that = this,
      usertoux = that.data.z_thumbs,
      a = that.data.imgUrlList,
      adminopenid = e.currentTarget.dataset.adminopenid,
      i = a.length,
      o = "patient/reply/saveReply?token=" + that.data.token;
    let listPatientBbsReplyVO = that.data.listPatientBbsReplyVO;
    let hfindex = that.data.huifuindex;
    if (that.data.pl_id) {
      var pl_id = that.data.pl_id
      console.log(pl_id)
      let reviewCommentsFlag = {
        // 判断楼主
        fromUid: 1,
        rid: 1,
        id: 1,
        fromUidName: that.data.z_name,
        content: that.data.rcontent,
        replyType: 'comment',
        hideFlag: 6
      };
      listPatientBbsReplyVO[hfindex].listPatientBbsReplyReplyVO.push(reviewCommentsFlag);
      that.setData({
        listPatientBbsReplyVO: listPatientBbsReplyVO,
        reviewCommentsFlag: !1,
      })
      var replyType = 'reply'
      var parentid = that.data.pl_id

    } else {
      var replyType = 'comment'
      var parentid = 0
    }
    //是否是贴主
    var pl_pic = that.data.imgUrlList
    var a_id = that.data.a_id
    var pl_content = that.data.rcontent
    var uniacid = app.siteInfo.uniacid;
    var data_arr = that.data.data_arr;
    var useropenid = wx.getStorageSync('openid') //用户openid 
    var name = that.data.z_name
    if (adminopenid == useropenid) {
      var author = 1
    } else {
      var author = 0
    }
    if (that.data.comFlag) {
      let comFlag = {
        userIcon: usertoux,
        // 判断楼主
        author: author,
        name: that.data.z_name,
        rtimeDay: that.data.time,
        rid: 1,
        ruid: 1,
        rcontent: that.data.rcontent,
        estimatePicSmallUrl: that.data.imgUrlList,
        listPatientBbsReplyReplyVO: [],
        allFlag: 1
      };
      listPatientBbsReplyVO.push(comFlag);
      that.setData({
        listPatientBbsReplyVO: listPatientBbsReplyVO,
        comFlag: !1,
        imgUrlList: []
      })
    }
    var data_arr1 = that.data.data_arr; //图片
    app.util.request({
      'url': 'entry/wxapp/share.pinglunadd',
      data: {
        pl_content: that.data.rcontent,
        adminopenid: adminopenid,
        useropenid: useropenid,
        a_id: a_id,
        data_arr1: data_arr1,
        types: 0,
        usertoux: usertoux,
        name: name,
        author: author,
        replyType: replyType,
        parentid: parentid,
      },
      success: function (res) {
        console.log(res)
        that.getAllpinglun(a_id)
      }
    })

  },
  toLike: function (e) {
    var a = this,
      i = e.currentTarget.dataset.index,
      o = e.currentTarget.dataset.status;
    let dianj = e.currentTarget.dataset.status;
    var a_id = a.data.a_id
    if (dianj == 0) {
      app.util.request({
        'url': 'entry/wxapp/share.userdianz',
        data: {
          op: 'dianzan',
          parentid: a_id,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          console.log(res)
          a.setData({
            dianj: 1
          })
        }
      })
    } else {
      wx.showToast({
        title: "点赞是严肃的，不可以反悔哦！",
        icon: "none",
        duration: 1500
      });
    }
  },
  moreState: function () {
    // var e = this;
    // e.data.loadingBoo && e.data.moreBoo && (e.setData({
    //   loadingBoo: !1
    // }), t.default.getDetails(e, 1));
  },
  bindscroll: function (t) {
    // t.detail.scrollTop > this.data.windowHeight ? this.setData({
    //   topFlag: !0
    // }) : this.setData({
    //   topFlag: !1
    // });
  },
  toTop: function (t) {
    this.setData({
      topFlag: !1,
      scrollTop: 0
    });
  },
  remove: function (t) {
    var a = this;
    var a_id = a.data.a_id
    wx.showModal({
      title: "确认删除动态吗",
      confirmColor: "#3b4ca9",
      success: function (t) {
        if (t.confirm) {
          app.util.request({
            'url': 'entry/wxapp/Share.deletecontent',
            data: {
              a_id: a_id
            },
            success: function (res) {
              console.log(res)
              wx.showToast({
                title: '删除成功',
                icon: 'none',
                duration: 2e3,
                success: function () {
                  setTimeout(function () {
                    wx.navigateBack({
                      detail: 1
                    })
                  }, 2000)
                }
              })
            },
            fail: function (err) {
              console.log(err)
            },
          })
        }
      }
    })
  },
  onLoad: function (options) {
    var that = this
    var a_id = options.a_id
    var time = util.formatTime(new Date());
    var bgc = wx.getStorageSync('color')
    var userInfo = wx.getStorageSync('userInfo')
    var useropenid = wx.getStorageSync('openid')
    console.log(userInfo)
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      a_id: a_id,
      userInfo: userInfo,
      time: time,
      bgc: bgc,
      useropenid: useropenid
    })
    this.getIfoverdian()
    this.getAllpinglun()
    app.util.request({
      'url': 'entry/wxapp/Share.datainfo',
      data: {
        a_id: a_id,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          detailList: res.data,
          z_thumbs: res.data.z_thumbs,
          z_name: res.data.z_name
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
    var uniacid = app.siteInfo.uniacid;
    app.util.request({
      'url': 'entry/wxapp/Share.url',
      'cachetime': '0',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data,
          uniacid: uniacid
        })
      },
    })
  },
  onReady: function () { },
  reviewComments: function (t) {
    console.log(t)
    this.data.pl_id = t.currentTarget.dataset.pl_id
    this.data.toUid = t.currentTarget.dataset.toid
    this.data.comment = "comment", console.log("回复你")
    this.setData({
      reviewCommentsFlag: !0,
      comFlag: !1,
      rcontent: "",
      huifuindex: t.currentTarget.dataset.index
    });
  },
  removepl(e) {
    var that = this
    var pl_id = e.currentTarget.dataset.pl_id
    var a_id = that.data.a_id
    wx.showModal({
      content: '确定删除该评论？',
      success: function (res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/share.deletepl',
            data: {
              pl_id: pl_id,
            },
            success: function (res) {
              console.log(res)
              that.getAllpinglun(a_id)
            }
          })
        }
      }
    })

  },
  reply: function (t) {
    this.data.comment = "reply", this.data.commentId = t.currentTarget.dataset.commentid,
      this.data.toUid = t.currentTarget.dataset.toid, this.setData({
        replyFlag: !0,
        comFlag: !1,
        rcontent: "",
        byReplyName: t.currentTarget.dataset.name
      });
  },
  mask: function () {
    this.setData({
      reviewCommentsFlag: !1,
      replyFlag: !1,
      huifuindex: ""
    });
  },
  removeBtn: function (t) {
    console.log(t);
    var a = this,
      i = t.currentTarget.dataset.index;
    var pl_id = t.currentTarget.dataset.pl_id
    var a_id = a.data.a_id
    wx.showModal({
      content: '确定删除该评论吗？',
      success: function (res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/share.deletepl',
            data: {
              pl_id: pl_id,
            },
            success: function (res) {
              console.log(res)
              a.getAllpinglun(a_id)
            }
          })
          wx.showToast({
            title: "删除成功",
            icon: "none",
            duration: 2e3
          })
        }
      }
    })

  },
  commentEach: function (a) {
    var i = this;
    wx.request({
      url: app.globalData.patient + "patient/reply/savePatBbsReplyReply",
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        rid: i.data.commentId,
        replyType: a,
        content: i.data.rcontent,
        toUid: i.data.toUid,
        token: i.data.token
      },
      success: function (e) {
        // console.log(e), 200 == e.data.code && 
        (i.setData({
          reviewCommentsFlag: !1,
          replyFlag: !1,
          rcontent: "",
          moreBoo: !0,
          page: 0
        }), t.default.getDetails(i, 0));
      }
    });
  },
  changeList: function (t) {
    console.log(t), this.data.fatherIndex = t.currentTarget.dataset.index;
    this.data.ruid = t.currentTarget.dataset.ruid;
  },
  lookMore: function (t) {
    console.log(t);
    var e = t.currentTarget.dataset.index;
    this.data.listPatientBbsReplyVO[e].allFlag = !0, this.data.listPatientBbsReplyVO[e].listPatientBbsReplyReplyVO.forEach(function (t) {
      t.hideFlag = !0;
    }), this.setData({
      listPatientBbsReplyVO: this.data.listPatientBbsReplyVO
    });
  },

  //查询当前分享的所有评论
  getAllpinglun: function () {
    var that = this
    var a_id = that.data.a_id
    app.util.request({
      'url': 'entry/wxapp/share.alllist',
      data: {
        a_id: a_id,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          listPatientBbsReplyVO: res.data
        })
      }
    })
  },
  getIfoverdian: function () {
    var that = this
    var a_id = that.data.a_id
    app.util.request({
      'url': 'entry/wxapp/share.user_if_dianz',
      data: {
        a_id: a_id,
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        console.log(res)
        if (res.data == 1) {
          that.setData({
            dianj: 1
          })
        }
      }
    })
  }
});